use actix_web::web;

use crate::{
    database::{table, DbPool},
    route::form::tag::{NewTagForm, TagForm},
    service::{class, ServiceError},
    srv_add, srv_del, srv_get_by_slug, srv_get_id, srv_get_id_in, srv_get_in_page,
    srv_get_in_page_by_foreign_key, srv_get_in_page_by_slug, srv_upd,
};

srv_add!(add, NewTagForm, table::tag::crud::create);
srv_upd!(upd, TagForm, table::tag::crud::update);
srv_del!(del, table::tag::crud::delete);

srv_get_id!(get_id, TagForm, table::tag::crud::read_id);
srv_get_id_in!(get_id_in, TagForm, table::tag::crud::read_id_in);
srv_get_by_slug!(get_by_slug, TagForm, table::tag::crud::read_by_slug);
srv_get_in_page!(
    get_in_page,
    TagForm,
    table::tag::crud::read_count_from_offset
);
srv_get_in_page_by_foreign_key!(
    get_in_page_by_category_id,
    TagForm,
    table::tag::crud::read_count_from_offset_by_cid
);
srv_get_in_page_by_slug!(
    get_in_page_by_category_slug,
    TagForm,
    class::category::get_by_slug,
    id,
    get_in_page_by_category_id
);
srv_get_in_page_by_slug!(
    get_in_page_by_tag_slug,
    TagForm,
    class::tag::get_by_slug,
    cid,
    get_in_page_by_category_id
);
